﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using NLog;
using ScrappyDB.BaseClasses;
using ScrappyDB.Utilities;

namespace ScrappyDB.IntegrationTests.Async
{
    [TestFixture]
    public class AsyncTest
    {
        private static readonly Logger Log = LogManager.GetCurrentClassLogger();

        [Test, Ignore]
        public void AsyncSaveTest()
        {
            const int testSize = 1000;
            var db = new Db();

            var d = db.Query<AsyncData>(null, true);
                db.Delete<AsyncData>(d);

            var data = new SdbCollection<AsyncData>();
            for (int x = 0; x < testSize; x++)
            {
                data.Add(new AsyncData()
                    {
                        Id = Guid.NewGuid(),
                        Data = x
                    });
            }

            data.SaveChanges( null);

            int count = 0;
            int steps = 0;

            while (count != testSize)
            {
                count = db.Count<AsyncData>(false);
                steps++;
                Log.Info("AsyncSaveTest: Step {0} - Count {1}",steps,count);

            }

            Assert.Inconclusive("You need to inspect logs to verify async functionality...");
            //Assert.IsTrue(steps > 1);
        }


    }

    public class AsyncData 
    {
        public Guid Id { get; set; }
        public int Data { get; set; }
    }
}
